<!DOCTYPE html>
<html lang="en">
<head>
    <title>路线车型管理</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/layui-2.4.2/src/css/layui.css">
    <script type="text/javascript" src="/jquery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/layui-2.4.2/src/layui.js"></script>
    <script type="text/javascript" src="/wangEditor.min.js"></script>
    <script type="text/javascript" src="/common.js"></script>

</head>
<body>
<div class="layui-row">
    <table id="route_model_view" lay-filter="route_model_view_filter">

    </table>
</div>
<form class="layui-form" id="edit_route_model" action="" style="display:none;margin-top: 30px;">
    <div class="layui-form-item">
        <label class="layui-form-label">价格(RMB)</label>
        <div class="layui-input-block" style="margin-right: 20px;">
            <input type="text" name="money" id="money" required  lay-verify="required" placeholder="请输入价格" class="layui-input">
        </div>
    </div>
</form>
<!--表格toobar模板-->
<script type="text/html" id="toolOper">
    <a class="layui-btn layui-btn-xs" lay-event="editMoney">编辑价格</a>
</script>
<script type="text/javascript">
</script>
<script>
    layui.use(['element', 'table', 'form', 'upload', 'laytpl'], function () {
        var table = layui.table;
        table.render({
            elem: '#route_model_view',
            url: '/routeModel/queryList',
            page: true,
            size: 10,
            limits: [10, 20, 50, 100],
            cols: [
                [
                    {field: 'id', title: '编号'},
                    {
                        field: 'money', title: '价格', templet: function (d) {
                            if (d.money == '' || d.money == undefined) {
                                return '请编辑价格,单位为RMB';
                            }
                            return d.money + 'RMB';
                        }
                    },
                    {field: 'routeId', title: '路线id'},
                    {field: 'routeName', title: '路线名称'},
                    {field: 'modelId', title: '车型id'},
                    {field: 'modelName', title: '车型名称'},
                    {field: 'right', align: 'center', title: '操作', toolbar: '#toolOper'}
                ]
            ],
            response: {
                status: 'errorCode',
                countName: 'total',
                dataName: 'data'
            }
        });

        table.on('tool(route_model_view_filter)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            var id=data.id;
            if (layEvent === 'editMoney') {
                $("#money").val('');
                layer.open({
                    type: 1,
                    area: ['300px', '200px'],
                    content: $("#edit_route_model"),
                    btn: ['保存', '取消'],
                    btnALign: 'c',
                    yes: function (index, layero) {
                        if ($("#money").val() == '') {
                            alert('请输入价格');
                            return;
                        }
                        var reg = /^\d+(\.\d{1,2})?$/;
                        if (!reg.test($("#money").val())) {
                            alert("请输入正确价格");
                            return false;
                        }
                        var data = {'id':id,'money':$("#money").val()};
                        $.ajax({
                            type: 'post',
                            data:data ,
                            url: '/routeModel/edit',
                            cache: false,
                            dataType: 'json',
                            success: function (data) {
                                layer.closeAll();
                                $(".layui-laypage-btn").click()
                            }
                        });
                    },
                });
            }
        });

    });
</script>

</body>
</html>